package com.swss.g.user.action;

import java.util.List;

import com.swss.g.base.BaseAction;
import com.swss.g.user.bean.Module;
import com.swss.g.user.bean.Popedom;
import com.swss.g.user.service.ModuleService;
import com.swss.g.user.service.PopedomService;
import com.swss.util.JSONHelper;
import com.swss.util.Pagination;

public class PopedomAction extends BaseAction {

	/**
	 * 
	 */
	private static final long serialVersionUID = 3016348148306946228L;
	/**
	 * bean
	 */

	private Popedom popedom;
	private int popedomIds[];

	@SuppressWarnings("unchecked")
	private Pagination pagination;
	private List<Module> modList;
	private List<Popedom> popeList;
	private String jsonPope;
	
	private String p1;
	private String p2;

	/**
	 * service
	 * 
	 * @return
	 */

	private PopedomService popedomService;
	private ModuleService moduleService;

	public String add() {
		try {
			System.out.println("=================22222222===");
			this.getPopedomService().save(popedom);

			// userList = this.getUserService().findAll();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return SUCCESS;
	};

	public String del() {
		try {

			this.getPopedomService().delete(popedom);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return SUCCESS;
	}

	public String delAll() {
		try {

			this.getPopedomService().delAllPopedom(this.getPopedomIds());
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return SUCCESS;
	}
	
	public String addInit() {

		try {
			if (pagination == null) {
				pagination = new Pagination();

			}

			pagination.setUsepage(false);
			pagination.setOrderBy("queue");
			pagination.setOrderType("asc");

			this.getPopedomService().findAll(pagination);
			popeList = pagination.getResult();
			jsonPope=JSONHelper.getJson(popeList);
			
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return "popeAdd";
	}

	public String saveInit() {

		try {
			if (pagination == null) {
				pagination = new Pagination();

			}

			pagination.setUsepage(false);
			pagination.setOrderBy("queue");
			pagination.setOrderType("asc");

			this.getPopedomService().findAll(pagination);
			popeList = pagination.getResult();
			jsonPope=JSONHelper.getJson(popeList);
			
			if (popedom != null) {
				popedom = this.popedomService.get(popedom.getId());
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return "popeSave";
	}

	public String save2(){
		System.out.println("===================");
		System.out.println(popedom.getPopedomName()+"???");
		return SUCCESS;
	}
	public String save() {
		System.out.println("===========2222========");
		System.out.println(popedom.getPopedomName());
		try { 
			
			this.getPopedomService().saveOrUpdate(popedom);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return SUCCESS;
	}

	public String init() {
		// 临时
		if (pagination == null) {
			pagination = new Pagination();

		}

		pagination.setUsepage(false);
		pagination.setOrderBy("queue");
		pagination.setOrderType("asc");
		try {
			this.getPopedomService().findAll(pagination);
			popeList = pagination.getResult();

		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return "popedom";
	}

	@SuppressWarnings("unchecked")
	public String findAllPopedom() {

		try {
			// 临时
			if (pagination == null) {
				pagination = new Pagination();

			}
			// pagination.setUsepage(false);
			// pagination.setOrderBy("queue");
			// pagination.setOrderType("asc");
			// pagination = this.getModuleService().findAll(pagination);
			// modList = pagination.getResult();

			this.getPopedomService().findAll(pagination);
			popeList = pagination.getResult();

		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return INPUT;
		}

		return SUCCESS;
	}

	public Popedom getPopedom() {
		return popedom;
	}

	public void setPopedom(Popedom popedom) {
		this.popedom = popedom;
	}

	public Pagination getPagination() {
		return pagination;
	}

	public void setPagination(Pagination pagination) {
		this.pagination = pagination;
	}

	public PopedomService getPopedomService() {
		return popedomService;
	}

	public void setPopedomService(PopedomService popedomService) {
		this.popedomService = popedomService;
	}

	public ModuleService getModuleService() {
		return moduleService;
	}

	public void setModuleService(ModuleService moduleService) {
		this.moduleService = moduleService;
	}

	public List<Module> getModList() {
		return modList;
	}

	public void setModList(List<Module> modList) {
		this.modList = modList;
	}

	public int[] getPopedomIds() {
		return popedomIds;
	}

	public void setPopedomIds(int[] popedomIds) {
		this.popedomIds = popedomIds;
	}

	public List<Popedom> getPopeList() {
		return popeList;
	}

	public void setPopeList(List<Popedom> popeList) {
		this.popeList = popeList;
	}

	public String getJsonPope() {
		return jsonPope;
	}

	public void setJsonPope(String jsonPope) {
		this.jsonPope = jsonPope;
	}

	public String getP1() {
		return p1;
	}

	public void setP1(String p1) {
		this.p1 = p1;
	}

	public String getP2() {
		return p2;
	}

	public void setP2(String p2) {
		this.p2 = p2;
	}

}
